/*      */ package net.sourceforge.appgen.editor;
/*      */ 
/*      */ import java.io.File;
/*      */ import java.io.IOException;
/*      */ import java.util.List;
/*      */ import net.sourceforge.appgen.connector.ProfileConnector;
/*      */ import net.sourceforge.appgen.databinding.DatabaseNameValidator;
/*      */ import net.sourceforge.appgen.databinding.DirectoryValidator;
/*      */ import net.sourceforge.appgen.databinding.PackageNameValidator;
/*      */ import net.sourceforge.appgen.databinding.StringToFileConverter;
/*      */ import net.sourceforge.appgen.job.GenerateFileJob;
/*      */ import net.sourceforge.appgen.job.GetEntityListJob;
/*      */ import net.sourceforge.appgen.model.ConnectionInformation;
/*      */ import net.sourceforge.appgen.model.Entity;
/*      */ import net.sourceforge.appgen.model.Field;
/*      */ import net.sourceforge.appgen.model.GenerationInformation;
/*      */ import net.sourceforge.appgen.model.MappingData;
/*      */ import net.sourceforge.appgen.model.ValueModifyListener;
/*      */ import net.sourceforge.appgen.support.EntityBaseNameEditingSupport;
/*      */ import net.sourceforge.appgen.support.EntityGeneratorEditingSupport;
/*      */ import net.sourceforge.appgen.support.EntityTableLabelProvider;
/*      */ import net.sourceforge.appgen.support.EntityTableNameEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldColumnLengthEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldColumnNameEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldColumnTypeEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldCreateEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldLobEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldNameEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldNullableEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldPkPositionEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldPositionEditingSupport;
/*      */ import net.sourceforge.appgen.support.FieldTableLabelProvider;
/*      */ import net.sourceforge.appgen.support.FieldTypeEditingSupport;
/*      */ import net.sourceforge.appgen.xml.XmlData;
/*      */ import net.sourceforge.appgen.xml.XmlDataException;
/*      */ import org.eclipse.core.databinding.DataBindingContext;
/*      */ import org.eclipse.core.databinding.UpdateValueStrategy;
/*      */ import org.eclipse.core.databinding.beans.BeansObservables;
/*      */ import org.eclipse.core.databinding.validation.IValidator;
/*      */ import org.eclipse.core.runtime.Assert;
/*      */ import org.eclipse.core.runtime.IProgressMonitor;
/*      */ import org.eclipse.core.runtime.IStatus;
/*      */ import org.eclipse.datatools.connectivity.db.generic.ui.wizard.NewJDBCFilteredCPWizard;
/*      */ import org.eclipse.jface.databinding.swt.SWTObservables;
/*      */ import org.eclipse.jface.dialogs.MessageDialog;
/*      */ import org.eclipse.jface.fieldassist.ControlDecoration;
/*      */ import org.eclipse.jface.fieldassist.FieldDecoration;
/*      */ import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
/*      */ import org.eclipse.jface.resource.ImageDescriptor;
/*      */ import org.eclipse.jface.resource.ImageRegistry;
/*      */ import org.eclipse.jface.text.IDocument;
/*      */ import org.eclipse.jface.viewers.ArrayContentProvider;
/*      */ import org.eclipse.jface.viewers.TableViewer;
/*      */ import org.eclipse.jface.viewers.TableViewerColumn;
/*      */ import org.eclipse.jface.wizard.WizardDialog;
/*      */ import org.eclipse.swt.custom.ScrolledComposite;
/*      */ import org.eclipse.swt.events.ModifyEvent;
/*      */ import org.eclipse.swt.events.ModifyListener;
/*      */ import org.eclipse.swt.events.SelectionAdapter;
/*      */ import org.eclipse.swt.events.SelectionEvent;
/*      */ import org.eclipse.swt.layout.FillLayout;
/*      */ import org.eclipse.swt.layout.GridData;
/*      */ import org.eclipse.swt.layout.GridLayout;
/*      */ import org.eclipse.swt.widgets.Button;
/*      */ import org.eclipse.swt.widgets.Combo;
/*      */ import org.eclipse.swt.widgets.Composite;
/*      */ import org.eclipse.swt.widgets.DirectoryDialog;
/*      */ import org.eclipse.swt.widgets.Label;
/*      */ import org.eclipse.swt.widgets.Table;
/*      */ import org.eclipse.swt.widgets.TableColumn;
/*      */ import org.eclipse.swt.widgets.TableItem;
/*      */ import org.eclipse.swt.widgets.Text;
/*      */ import org.eclipse.ui.IEditorInput;
/*      */ import org.eclipse.ui.IEditorSite;
/*      */ import org.eclipse.ui.IWorkbench;
/*      */ import org.eclipse.ui.IWorkbenchPartSite;
/*      */ import org.eclipse.ui.IWorkbenchWindow;
/*      */ import org.eclipse.ui.PartInitException;
/*      */ import org.eclipse.ui.PlatformUI;
/*      */ import org.eclipse.ui.console.ConsolePlugin;
/*      */ import org.eclipse.ui.console.IConsole;
/*      */ import org.eclipse.ui.console.IConsoleManager;
/*      */ import org.eclipse.ui.console.MessageConsole;
/*      */ import org.eclipse.ui.console.MessageConsoleStream;
/*      */ import org.eclipse.ui.editors.text.TextEditor;
/*      */ import org.eclipse.ui.part.FileEditorInput;
/*      */ import org.eclipse.ui.part.MultiPageEditorPart;
/*      */ import org.eclipse.ui.texteditor.IDocumentProvider;
/*      */ 
/*      */ public class MappingDataEditor extends MultiPageEditorPart
/*      */ {
/*  112 */   private static final FieldDecoration DEC_ERROR = FieldDecorationRegistry.getDefault().getFieldDecoration("DEC_ERROR");
/*      */   private ImageRegistry imageRegistry;
/*      */   public static final String CHECKED_IMAGE = "header_checked";
/*      */   public static final String UNCHECKED_IMAGE = "header_unchecked";
/*      */   private MappingData mappingData;
/*      */   private TextEditor textEditor;
/*      */   private Entity currentEntity;
/*  126 */   private boolean allEntitySelection = false;
/*      */   private MessageConsole console;
/*      */   private MessageConsoleStream stream;
/*      */   private IConsoleManager consoleManager;
/*      */   private Combo databaseNameCombo;
/*      */   private Text databaseSchemaText;
/*      */   private ControlDecoration databaseNameControlDecoration;
/*      */   private IValidator databaseNameValidator;
/*      */   private TableViewer entityTableViewer;
/*      */   private TableViewer fieldTableViewer;
/*      */   private Text outputDirText;
/*      */   private Text packageNameText;
/*      */   private ControlDecoration outputDirControlDecoration;
/*      */   private IValidator outputDirValidator;
/*      */   private ControlDecoration packageNameControlDecoration;
/*      */   private IValidator packageNameValidator;
/*      */   private Button connectionButton;
/*      */   private Button generationButton;
/*      */   private Button addEntityButton;
/*      */   private Button removeEntityButton;
/*      */   private Button addFieldButton;
/*      */   private Button removeFieldButton;
/*      */   private DataBindingContext dataBindingContext;
/*      */   private boolean dirty;
/*      */   private MappingDataEditor editor;
/*      */ 
/*      */   public MappingDataEditor()
/*      */   {
/*  167 */     this.mappingData = new MappingData();
/*      */ 
/*  169 */     this.consoleManager = ConsolePlugin.getDefault().getConsoleManager();
/*  170 */     this.console = new MessageConsole("AppGen", null);
/*  171 */     this.stream = this.console.newMessageStream();
/*  172 */     this.consoleManager.addConsoles(new IConsole[] { this.console });
/*  173 */     this.consoleManager.showConsoleView(this.console);
/*      */ 
/*  175 */     initImageRegistry();
/*      */ 
/*  177 */     this.editor = this;
/*      */   }
/*      */ 
/*      */   private void initImageRegistry() {
/*  181 */     this.imageRegistry = new ImageRegistry();
/*      */ 
/*  183 */     String iconPath = "icon/";
/*  184 */     this.imageRegistry.put("header_checked", ImageDescriptor.createFromFile(MappingDataEditor.class, iconPath + "header_checked" + ".gif"));
/*  185 */     this.imageRegistry.put("header_unchecked", ImageDescriptor.createFromFile(MappingDataEditor.class, iconPath + "header_unchecked" + ".gif"));
/*      */   }
/*      */ 
/*      */   public void init(IEditorSite site, IEditorInput input) throws PartInitException
/*      */   {
/*  190 */     setSite(site);
/*  191 */     setInput(input);
/*      */ 
/*  193 */     setPartName(input.getName());
/*      */ 
/*  195 */     loadData(input);
/*      */   }
/*      */ 
/*      */   public void dispose()
/*      */   {
/*  200 */     if (this.stream != null)
/*      */       try {
/*  202 */         this.stream.close();
/*      */       }
/*      */       catch (IOException localIOException)
/*      */       {
/*      */       }
/*  207 */     if (this.consoleManager != null) {
/*  208 */       this.consoleManager.removeConsoles(new IConsole[] { this.console });
/*      */     }
/*      */ 
/*  211 */     if (this.dataBindingContext != null) {
/*  212 */       this.dataBindingContext.dispose();
/*      */     }
/*      */ 
/*  215 */     if (this.imageRegistry != null) {
/*  216 */       this.imageRegistry.dispose();
/*      */     }
/*      */ 
/*  219 */     super.dispose();
/*      */   }
/*      */ 
/*      */   public boolean isSaveAsAllowed()
/*      */   {
/*  224 */     return true;
/*      */   }
/*      */ 
/*      */   public MessageConsole getConsole() {
/*  228 */     return this.console;
/*      */   }
/*      */ 
/*      */   public void loadData(IEditorInput input) {
/*  232 */     FileEditorInput fileEditorInput = (FileEditorInput)input;
/*  233 */     File file = new File(fileEditorInput.getURI());
/*      */ 
/*  235 */     XmlData xmlData = new XmlData();
/*      */     try
/*      */     {
/*  238 */       xmlData.loadFromXml(file);
/*      */ 
/*  240 */       this.mappingData = xmlData.getMappingData();
/*      */ 
/*  242 */       this.mappingData.addValueModifyListener(new DataModifyListener());
/*      */     } catch (Exception e) {
/*  244 */       MessageDialog.openError(getSite().getShell(), "Error - loadData", e.getMessage());
/*      */     }
/*      */   }
/*      */ 
/*      */   public void onEntityListChanged(List<Entity> entityList) {
/*  249 */     this.mappingData.setEntityList(entityList);
/*      */ 
/*  251 */     this.mappingData.addValueModifyListener(new DataModifyListener());
/*      */ 
/*  253 */     showEntityList(this.mappingData.getEntityList());
/*      */ 
/*  255 */     this.dirty = true;
/*  256 */     firePropertyChange(257);
/*      */   }
/*      */ 
/*      */   private void createConnectionInputPart(Composite contentComponent)
/*      */   {
/*  262 */     Label heading = new Label(contentComponent, 16385);
/*  263 */     heading.setText("Connection info");
/*  264 */     GridData gridData = new GridData(4, 16777216, true, false);
/*  265 */     gridData.horizontalSpan = 3;
/*  266 */     heading.setLayoutData(gridData);
/*      */ 
/*  268 */     Label databaseLabel = new Label(contentComponent, 16384);
/*  269 */     databaseLabel.setText("Database Profile:");
/*      */ 
/*  271 */     createDatabaseNameCombo(contentComponent);
/*  272 */     gridData = new GridData(4, 16777216, true, false);
/*  273 */     this.databaseNameCombo.setLayoutData(gridData);
/*      */ 
/*  275 */     Button createNewProfileButton = new Button(contentComponent, 524288);
/*  276 */     createNewProfileButton.setText("New...");
/*      */ 
/*  278 */     createNewProfileButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent e) {
/*  281 */         NewJDBCFilteredCPWizard wizard = new NewJDBCFilteredCPWizard();
/*  282 */         wizard.init(PlatformUI.getWorkbench(), null);
/*  283 */         WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
/*  284 */         int value = dialog.open();
/*  285 */         if (value == 0)
/*  286 */           MappingDataEditor.this.refreshDatabaseNameCombo();
/*      */       }
/*      */     });
/*  291 */     Label schemaLabel = new Label(contentComponent, 16384);
/*  292 */     schemaLabel.setText("Database Schema:");
/*      */ 
/*  294 */     this.databaseSchemaText = new Text(contentComponent, 2052);
/*      */ 
/*  296 */     gridData = new GridData(4, 16777216, true, false);
/*  297 */     gridData.horizontalSpan = 2;
/*  298 */     this.databaseSchemaText.setLayoutData(gridData);
/*      */   }
/*      */ 
/*      */   private void createConnectionButtonPart(final Composite contentComponent)
/*      */   {
/*  304 */     this.connectionButton = new Button(contentComponent, 8);
/*  305 */     this.connectionButton.setText("Initialize entities from tables");
/*  306 */     GridData gridData = new GridData(16384, 16777216, false, false);
/*  307 */     gridData.horizontalSpan = 3;
/*  308 */     this.connectionButton.setLayoutData(gridData);
/*      */ 
/*  310 */     this.connectionButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent event) {
/*  313 */         ConnectionInformation connectionInformation = MappingDataEditor.this.mappingData.getConnectionInformation();
/*      */ 
/*  315 */         if (!MappingDataEditor.this.validateConnectionInformation()) {
/*  316 */           return;
/*      */         }
/*      */         try
/*      */         {
/*  320 */           contentComponent.setEnabled(false);
/*      */ 
/*  322 */           GetEntityListJob getEntityListJob = new GetEntityListJob(connectionInformation, MappingDataEditor.this.editor, "Parse database - " + connectionInformation.getName());
/*  323 */           getEntityListJob.schedule();
/*      */         } finally {
/*  325 */           contentComponent.setEnabled(true);
/*      */         }
/*      */       } } );
/*      */   }
/*      */ 
/*      */   private void createEntityButtonPart(Composite contentComponent) {
/*  332 */     GridData gridData = new GridData(16384, 16777216, false, false);
/*  333 */     gridData.horizontalSpan = 3;
/*      */ 
/*  335 */     Composite composite = new Composite(contentComponent, 0);
/*  336 */     composite.setLayoutData(gridData);
/*  337 */     composite.setLayout(new FillLayout());
/*      */ 
/*  339 */     this.addEntityButton = new Button(composite, 8);
/*  340 */     this.addEntityButton.setText("Add entity");
/*      */ 
/*  342 */     this.addEntityButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent event) {
/*  345 */         Entity entity = new Entity();
/*  346 */         entity.setCreate(MappingDataEditor.this.allEntitySelection);
/*  347 */         MappingDataEditor.this.mappingData.getEntityList().add(entity);
/*      */ 
/*  349 */         MappingDataEditor.this.mappingData.addValueModifyListener(new MappingDataEditor.DataModifyListener());
/*      */ 
/*  351 */         MappingDataEditor.this.entityTableViewer.setInput(MappingDataEditor.this.mappingData.getEntityList());
/*  352 */         MappingDataEditor.this.entityTableViewer.getTable().setSelection(MappingDataEditor.this.mappingData.getEntityList().size() - 1);
/*      */ 
/*  354 */         MappingDataEditor.this.fieldTableViewer.setInput(entity.getFieldList());
/*      */ 
/*  356 */         MappingDataEditor.this.currentEntity = entity;
/*      */ 
/*  358 */         MappingDataEditor.this.dirty = true;
/*  359 */         MappingDataEditor.this.firePropertyChange(257);
/*      */       }
/*      */     });
/*  363 */     this.removeEntityButton = new Button(composite, 8);
/*  364 */     this.removeEntityButton.setText("Remove entity");
/*      */ 
/*  366 */     this.removeEntityButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent event) {
/*  369 */         if (MappingDataEditor.this.currentEntity == null) {
/*  370 */           MessageDialog.openError(MappingDataEditor.this.getSite().getShell(), "Invalid", "Select entity.");
/*  371 */           return;
/*      */         }
/*      */ 
/*  374 */         boolean confirm = MessageDialog.openConfirm(MappingDataEditor.this.getSite().getShell(), "confirm", "Delete selected entity?");
/*      */ 
/*  376 */         if (!confirm) {
/*  377 */           return;
/*      */         }
/*      */ 
/*  380 */         Table entityTable = MappingDataEditor.this.entityTableViewer.getTable();
/*      */ 
/*  382 */         TableItem[] tableItems = entityTable.getItems();
/*  383 */         for (int i = 0; i < tableItems.length; i++) {
/*  384 */           Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/*  386 */           if (MappingDataEditor.this.currentEntity == tableEntity) {
/*  387 */             MappingDataEditor.this.mappingData.getEntityList().remove(i);
/*  388 */             break;
/*      */           }
/*      */         }
/*      */ 
/*  392 */         MappingDataEditor.this.entityTableViewer.setInput(MappingDataEditor.this.mappingData.getEntityList());
/*  393 */         MappingDataEditor.this.fieldTableViewer.setInput(null);
/*      */ 
/*  395 */         MappingDataEditor.this.entityTableViewer.getTable().setSelection(-1);
/*  396 */         MappingDataEditor.this.fieldTableViewer.getTable().setSelection(-1);
/*      */ 
/*  398 */         MappingDataEditor.this.currentEntity = null;
/*      */ 
/*  400 */         MappingDataEditor.this.dirty = true;
/*  401 */         MappingDataEditor.this.firePropertyChange(257);
/*      */       } } );
/*      */   }
/*      */ 
/*      */   private void createFieldButtonPart(Composite contentComponent) {
/*  407 */     GridData gridData = new GridData(16384, 16777216, false, false);
/*  408 */     gridData.horizontalSpan = 3;
/*      */ 
/*  410 */     Composite composite = new Composite(contentComponent, 0);
/*  411 */     composite.setLayoutData(gridData);
/*  412 */     composite.setLayout(new FillLayout());
/*      */ 
/*  414 */     this.addFieldButton = new Button(composite, 8);
/*  415 */     this.addFieldButton.setText("Add field");
/*      */ 
/*  417 */     this.addFieldButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent event) {
/*  420 */         if (MappingDataEditor.this.currentEntity == null) {
/*  421 */           MessageDialog.openError(MappingDataEditor.this.getSite().getShell(), "Invalid", "Select entity.");
/*  422 */           return;
/*      */         }
/*      */ 
/*  425 */         Field field = new Field(MappingDataEditor.this.currentEntity);
/*  426 */         field.setCreate(MappingDataEditor.this.currentEntity.isAllFieldSelection());
/*  427 */         MappingDataEditor.this.currentEntity.getFieldList().add(field);
/*      */ 
/*  429 */         MappingDataEditor.this.mappingData.addValueModifyListener(new MappingDataEditor.DataModifyListener());
/*      */ 
/*  431 */         MappingDataEditor.this.fieldTableViewer.setInput(MappingDataEditor.this.currentEntity.getFieldList());
/*  432 */         MappingDataEditor.this.fieldTableViewer.getTable().setSelection(MappingDataEditor.this.currentEntity.getFieldList().size() - 1);
/*      */ 
/*  434 */         MappingDataEditor.this.dirty = true;
/*  435 */         MappingDataEditor.this.firePropertyChange(257);
/*      */       }
/*      */     });
/*  439 */     this.removeFieldButton = new Button(composite, 8);
/*  440 */     this.removeFieldButton.setText("Remove field");
/*      */ 
/*  442 */     this.removeFieldButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent event) {
/*  445 */         Field currentField = null;
/*      */ 
/*  447 */         TableItem[] selectedTableItems = MappingDataEditor.this.fieldTableViewer.getTable().getSelection();
/*  448 */         if (selectedTableItems != null) {
/*  449 */           currentField = (Field)selectedTableItems[0].getData();
/*      */         }
/*      */ 
/*  452 */         if (currentField == null) {
/*  453 */           MessageDialog.openError(MappingDataEditor.this.getSite().getShell(), "Invalid", "Select field.");
/*  454 */           return;
/*      */         }
/*      */ 
/*  457 */         TableItem[] tableItems = MappingDataEditor.this.fieldTableViewer.getTable().getItems();
/*  458 */         for (int i = 0; i < tableItems.length; i++) {
/*  459 */           if (tableItems[i].getData() == currentField) {
/*  460 */             currentField.getEntity().getFieldList().remove(i);
/*  461 */             break;
/*      */           }
/*      */         }
/*      */ 
/*  465 */         MappingDataEditor.this.fieldTableViewer.setInput(currentField.getEntity().getFieldList());
/*      */ 
/*  467 */         MappingDataEditor.this.fieldTableViewer.getTable().setSelection(-1);
/*      */ 
/*  469 */         MappingDataEditor.this.dirty = true;
/*  470 */         MappingDataEditor.this.firePropertyChange(257);
/*      */       }
/*      */     });
/*      */   }
/*      */ 
/*      */   private void createEntityTable(Composite parent)
/*      */   {
/*  478 */     this.entityTableViewer = new TableViewer(parent, 68356);
/*  479 */     final Table entityTable = this.entityTableViewer.getTable();
/*  480 */     entityTable.setHeaderVisible(true);
/*  481 */     entityTable.setLinesVisible(true);
/*      */ 
/*  483 */     String[] columnNames = { "", "Table name", "Base name" };
/*  484 */     int[] columnWidths = { 40, 310, 310 };
/*  485 */     int[] columnAlignments = { 16384, 16384, 16384 };
/*      */ 
/*  487 */     for (int i = 0; i < columnNames.length; i++) {
/*  488 */       TableViewerColumn column = new TableViewerColumn(this.entityTableViewer, 0);
/*      */ 
/*  490 */       TableColumn tableColumn = column.getColumn();
/*  491 */       tableColumn.setText(columnNames[i]);
/*  492 */       tableColumn.setWidth(columnWidths[i]);
/*  493 */       tableColumn.setAlignment(columnAlignments[i]);
/*      */ 
/*  495 */       if (i == 0) {
/*  496 */         tableColumn.setResizable(false);
/*      */ 
/*  498 */         tableColumn.addSelectionListener(new SelectionAdapter()
/*      */         {
/*      */           public void widgetSelected(SelectionEvent e) {
/*  501 */             MappingDataEditor.this.allEntitySelection = (!MappingDataEditor.this.allEntitySelection);
/*  502 */             MappingDataEditor.this.changeAllEntitySelection();
/*      */           }
/*      */         });
/*  506 */         column.setEditingSupport(new EntityGeneratorEditingSupport(this.entityTableViewer));
/*      */       }
/*  508 */       if (i == 1) {
/*  509 */         column.setEditingSupport(new EntityTableNameEditingSupport(this.entityTableViewer));
/*      */       }
/*  511 */       if (i == 2) {
/*  512 */         column.setEditingSupport(new EntityBaseNameEditingSupport(this.entityTableViewer));
/*      */       }
/*      */     }
/*      */ 
/*  516 */     this.entityTableViewer.setLabelProvider(new EntityTableLabelProvider());
/*  517 */     this.entityTableViewer.setContentProvider(new ArrayContentProvider());
/*      */ 
/*  519 */     GridData gridData = new GridData(4, 16777216, true, false);
/*  520 */     gridData.horizontalSpan = 3;
/*  521 */     gridData.heightHint = 100;
/*  522 */     entityTable.setLayoutData(gridData);
/*      */ 
/*  524 */     entityTable.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent e) {
/*  527 */         TableItem tableItem = (TableItem)e.item;
/*      */ 
/*  529 */         TableItem[] tableItems = entityTable.getItems();
/*  530 */         for (int i = 0; i < tableItems.length; i++) {
/*  531 */           if (tableItems[i] == tableItem) {
/*  532 */             MappingDataEditor.this.currentEntity = ((Entity)MappingDataEditor.this.mappingData.getEntityList().get(i));
/*  533 */             MappingDataEditor.this.fieldTableViewer.setInput(MappingDataEditor.this.currentEntity.getFieldList());
/*      */           }
/*      */         }
/*      */ 
/*  537 */         TableColumn tableColumn = MappingDataEditor.this.fieldTableViewer.getTable().getColumn(0);
/*  538 */         tableColumn.setImage((MappingDataEditor.this.currentEntity != null) && (MappingDataEditor.this.currentEntity.isAllFieldSelection()) ? MappingDataEditor.this.imageRegistry.get("header_checked") : MappingDataEditor.this.imageRegistry.get("header_unchecked"));
/*      */       }
/*      */     });
/*  542 */     TableColumn tableColumn = this.entityTableViewer.getTable().getColumn(0);
/*  543 */     tableColumn.setImage(this.allEntitySelection ? this.imageRegistry.get("header_checked") : this.imageRegistry.get("header_unchecked"));
/*      */   }
/*      */ 
/*      */   private void createFieldTable(Composite parent)
/*      */   {
/*  549 */     this.fieldTableViewer = new TableViewer(parent, 68356);
/*  550 */     Table fieldTable = this.fieldTableViewer.getTable();
/*  551 */     fieldTable.setHeaderVisible(true);
/*  552 */     fieldTable.setLinesVisible(true);
/*      */ 
/*  554 */     String[] columnNames = { "", "Column name", "Column type", "Column size", "PK", "Nullable", "Lob", "Field name", "Field type", "", "" };
/*  555 */     int[] columnWidths = { 40, 150, 100, 100, 50, 70, 60, 130, 130, 25, 25 };
/*  556 */     int[] columnAlignments = { 16777216, 16384, 16384, 131072, 131072, 131072, 131072, 16384, 16384, 16777216, 16777216 };
/*      */ 
/*  558 */     for (int i = 0; i < columnNames.length; i++) {
/*  559 */       TableViewerColumn column = new TableViewerColumn(this.fieldTableViewer, 0);
/*      */ 
/*  561 */       TableColumn tableColumn = column.getColumn();
/*  562 */       tableColumn.setText(columnNames[i]);
/*  563 */       tableColumn.setWidth(columnWidths[i]);
/*  564 */       tableColumn.setAlignment(columnAlignments[i]);
/*      */ 
/*  566 */       if (i == 0) {
/*  567 */         tableColumn.setResizable(false);
/*      */ 
/*  569 */         tableColumn.addSelectionListener(new SelectionAdapter()
/*      */         {
/*      */           public void widgetSelected(SelectionEvent e) {
/*  572 */             if (MappingDataEditor.this.currentEntity != null) {
/*  573 */               MappingDataEditor.this.currentEntity.setAllFieldSelection(!MappingDataEditor.this.currentEntity.isAllFieldSelection());
/*      */ 
/*  575 */               MappingDataEditor.this.changeAllFieldSelection();
/*      */             }
/*      */           }
/*      */         });
/*  580 */         column.setEditingSupport(new FieldCreateEditingSupport(this.fieldTableViewer));
/*      */       }
/*  582 */       if (i == 1) {
/*  583 */         column.setEditingSupport(new FieldColumnNameEditingSupport(this.fieldTableViewer));
/*      */       }
/*  585 */       if (i == 2) {
/*  586 */         column.setEditingSupport(new FieldColumnTypeEditingSupport(this.fieldTableViewer));
/*      */       }
/*  588 */       if (i == 3) {
/*  589 */         column.setEditingSupport(new FieldColumnLengthEditingSupport(this.fieldTableViewer));
/*      */       }
/*  591 */       if (i == 4) {
/*  592 */         column.setEditingSupport(new FieldPkPositionEditingSupport(this.fieldTableViewer));
/*      */       }
/*  594 */       if (i == 5) {
/*  595 */         column.setEditingSupport(new FieldNullableEditingSupport(this.fieldTableViewer));
/*      */       }
/*  597 */       if (i == 6) {
/*  598 */         column.setEditingSupport(new FieldLobEditingSupport(this.fieldTableViewer));
/*      */       }
/*  600 */       if (i == 7) {
/*  601 */         column.setEditingSupport(new FieldNameEditingSupport(this.fieldTableViewer));
/*      */       }
/*  603 */       if (i == 8) {
/*  604 */         column.setEditingSupport(new FieldTypeEditingSupport(this.fieldTableViewer));
/*      */       }
/*  606 */       if (i == 9) {
/*  607 */         tableColumn.setResizable(false);
/*  608 */         column.setEditingSupport(new FieldPositionEditingSupport(this.fieldTableViewer, false));
/*      */       }
/*  610 */       if (i == 10) {
/*  611 */         tableColumn.setResizable(false);
/*  612 */         column.setEditingSupport(new FieldPositionEditingSupport(this.fieldTableViewer, true));
/*      */       }
/*      */ 
/*  615 */       changeAllFieldSelection();
/*      */     }
/*      */ 
/*  618 */     this.fieldTableViewer.setLabelProvider(new FieldTableLabelProvider());
/*  619 */     this.fieldTableViewer.setContentProvider(new ArrayContentProvider());
/*      */ 
/*  621 */     GridData gridData = new GridData(4, 16777216, true, false);
/*  622 */     gridData.horizontalSpan = 3;
/*  623 */     gridData.heightHint = 150;
/*  624 */     fieldTable.setLayoutData(gridData);
/*      */   }
/*      */ 
/*      */   private void createGenerationInputPart(Composite contentComponent)
/*      */   {
/*  630 */     Label outputDirLabel = new Label(contentComponent, 16384);
/*  631 */     outputDirLabel.setText("Output files dir:");
/*      */ 
/*  633 */     createOutputDirText(contentComponent);
/*  634 */     GridData gridData = new GridData(4, 16777216, true, false);
/*  635 */     this.outputDirText.setLayoutData(gridData);
/*      */ 
/*  637 */     Button outputDirFileButton = new Button(contentComponent, 524288);
/*  638 */     outputDirFileButton.setText("Browse...");
/*      */ 
/*  640 */     outputDirFileButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent e) {
/*  643 */         DirectoryDialog directoryDialog = new DirectoryDialog(MappingDataEditor.this.outputDirText.getShell(), 4098);
/*  644 */         String selected = directoryDialog.open();
/*  645 */         MappingDataEditor.this.outputDirText.setText(selected);
/*      */       }
/*      */     });
/*  649 */     Label projectPackageNameLabel = new Label(contentComponent, 16384);
/*  650 */     projectPackageNameLabel.setText("Project package:");
/*      */ 
/*  652 */     createPackageNameText(contentComponent);
/*  653 */     gridData = new GridData(4, 16777216, true, false);
/*  654 */     gridData.horizontalSpan = 2;
/*  655 */     this.packageNameText.setLayoutData(gridData);
/*      */   }
/*      */ 
/*      */   private void createDatabaseNameCombo(Composite contentComponent) {
/*  659 */     this.databaseNameCombo = new Combo(contentComponent, 8);
/*      */ 
/*  661 */     refreshDatabaseNameCombo();
/*      */ 
/*  663 */     this.databaseNameControlDecoration = new ControlDecoration(this.databaseNameCombo, 16512);
/*  664 */     this.databaseNameControlDecoration.setImage(DEC_ERROR.getImage());
/*      */ 
/*  666 */     this.databaseNameValidator = new DatabaseNameValidator();
/*      */ 
/*  668 */     addModifyListener(contentComponent, this.databaseNameCombo, this.databaseNameControlDecoration, this.databaseNameValidator);
/*      */   }
/*      */ 
/*      */   private void refreshDatabaseNameCombo() {
/*  672 */     String[] profileNames = ProfileConnector.getProfileNames();
/*      */ 
/*  674 */     this.databaseNameCombo.setItems(profileNames);
/*      */   }
/*      */ 
/*      */   private void createOutputDirText(Composite contentComponent) {
/*  678 */     this.outputDirText = new Text(contentComponent, 2052);
/*      */ 
/*  680 */     this.outputDirControlDecoration = new ControlDecoration(this.outputDirText, 16512);
/*  681 */     this.outputDirControlDecoration.setImage(DEC_ERROR.getImage());
/*      */ 
/*  683 */     this.outputDirValidator = new DirectoryValidator();
/*      */ 
/*  685 */     addModifyListener(contentComponent, this.outputDirText, this.outputDirControlDecoration, this.outputDirValidator);
/*      */   }
/*      */ 
/*      */   private void createPackageNameText(Composite contentComponent) {
/*  689 */     this.packageNameText = new Text(contentComponent, 2052);
/*      */ 
/*  691 */     this.packageNameControlDecoration = new ControlDecoration(this.packageNameText, 16512);
/*  692 */     this.packageNameControlDecoration.setImage(DEC_ERROR.getImage());
/*      */ 
/*  694 */     this.packageNameValidator = new PackageNameValidator();
/*      */ 
/*  696 */     addModifyListener(contentComponent, this.packageNameText, this.packageNameControlDecoration, this.packageNameValidator);
/*      */   }
/*      */ 
/*      */   private void addModifyListener(Composite contentComponent, final Combo combo, final ControlDecoration controlDecoration, final IValidator validator) {
/*  700 */     Assert.isNotNull(combo);
/*  701 */     Assert.isNotNull(controlDecoration);
/*  702 */     Assert.isNotNull(validator);
/*      */ 
/*  704 */     combo.addModifyListener(new ModifyListener() {
/*      */       public void modifyText(ModifyEvent e) {
/*  706 */         IStatus status = validator.validate(combo.getText());
/*  707 */         if (status.isOK()) {
/*  708 */           controlDecoration.hide();
/*      */         } else {
/*  710 */           controlDecoration.setDescriptionText(status.getMessage());
/*  711 */          controlDecoration.show();
/*      */         }
/*      */       } } );
/*      */   }
/*      */ 
/*      */   private void addModifyListener(Composite contentComponent, final Text text, final ControlDecoration controlDecoration, final IValidator validator) {
/*  718 */     Assert.isNotNull(text);
/*  719 */     Assert.isNotNull(controlDecoration);
/*  720 */     Assert.isNotNull(validator);
/*      */ 
/*  722 */     text.addModifyListener(new ModifyListener() {
/*      */       public void modifyText(ModifyEvent e) {
/*  724 */         IStatus status = validator.validate(text.getText());
/*  725 */         if (status.isOK()) {
/*  726 */           controlDecoration.hide();
/*      */         } else {
/*  728 */           controlDecoration.setDescriptionText(status.getMessage());
/*  729 */           controlDecoration.show();
/*      */         }
/*      */       }
/*      */     });
/*      */   }
/*      */ 
/*      */   private void createGenerationButtonPart(final Composite contentComponent)
/*      */   {
/*  738 */     this.generationButton = new Button(contentComponent, 8);
/*  739 */     this.generationButton.setText("Generate source files");
/*  740 */     GridData gridData = new GridData(16384, 16777216, false, false);
/*  741 */     gridData.horizontalSpan = 3;
/*  742 */     this.generationButton.setLayoutData(gridData);
/*      */ 
/*  744 */     this.generationButton.addSelectionListener(new SelectionAdapter()
/*      */     {
/*      */       public void widgetSelected(SelectionEvent evnet) {
/*  747 */         if (!MappingDataEditor.this.validateGenerationInformation()) {
/*  748 */           return;
/*      */         }
/*      */         try
/*      */         {
/*  752 */           contentComponent.setEnabled(false);
/*      */ 
/*  754 */           GenerateFileJob GenerateFileAction = new GenerateFileJob(MappingDataEditor.this.mappingData, MappingDataEditor.this, "Generate file...");
/*  755 */           GenerateFileAction.schedule();
/*      */         }
/*      */         finally
/*      */         {
/*  761 */           contentComponent.setEnabled(true);
/*      */         }
/*      */       }
/*      */     });
/*      */   }
/*      */ 
/*      */   private void bindValues() {
/*  769 */     this.dataBindingContext = new DataBindingContext();
/*      */ 
/*  771 */     UpdateValueStrategy fileUpdateValueStrategy = new UpdateValueStrategy();
/*  772 */     fileUpdateValueStrategy.setConverter(new StringToFileConverter());
/*      */ 
/*  774 */     ConnectionInformation connectionInformation = this.mappingData.getConnectionInformation();
/*  775 */     GenerationInformation generationInformation = this.mappingData.getGenerationInformation();
/*      */ 
/*  777 */     this.dataBindingContext.bindValue(SWTObservables.observeSelection(this.databaseNameCombo), BeansObservables.observeValue(connectionInformation, "name"), null, null);
/*  778 */     this.dataBindingContext.bindValue(SWTObservables.observeText(this.databaseSchemaText, 24), BeansObservables.observeValue(connectionInformation, "schema"), null, null);
/*      */ 
/*  780 */     this.dataBindingContext.bindValue(SWTObservables.observeText(this.outputDirText, 24), BeansObservables.observeValue(generationInformation, "outputDir"), fileUpdateValueStrategy, null);
/*  781 */     this.dataBindingContext.bindValue(SWTObservables.observeText(this.packageNameText, 24), BeansObservables.observeValue(generationInformation, "packageName"), null, null);
/*      */   }
/*      */ 
/*      */   private void changeAllEntitySelection() {
/*  785 */     TableColumn tableColumn = this.entityTableViewer.getTable().getColumn(0);
/*  786 */     tableColumn.setImage(this.allEntitySelection ? this.imageRegistry.get("header_checked") : this.imageRegistry.get("header_unchecked"));
/*      */ 
/*  788 */     List<Entity> entityList = this.mappingData.getEntityList();
/*      */ 
/*  790 */     if (entityList != null) {
/*  791 */       for (Entity entity : entityList) {
/*  792 */         entity.setCreate(this.allEntitySelection);
/*      */       }
/*      */ 
/*  795 */       this.entityTableViewer.setInput(entityList);
/*      */     }
/*      */   }
/*      */ 
/*      */   private void changeAllFieldSelection() {
/*  800 */     TableColumn tableColumn = this.fieldTableViewer.getTable().getColumn(0);
/*  801 */     tableColumn.setImage((this.currentEntity != null) && (this.currentEntity.isAllFieldSelection()) ? this.imageRegistry.get("header_checked") : this.imageRegistry.get("header_unchecked"));
/*      */ 
/*  803 */     if ((this.currentEntity != null) && (this.currentEntity.getFieldList() != null)) {
/*  804 */       for (Field field : this.currentEntity.getFieldList()) {
/*  805 */         field.setCreate(this.currentEntity.isAllFieldSelection());
/*      */       }
/*      */ 
/*  808 */       this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */     }
/*      */   }
/*      */ 
/*      */   private boolean validateConnectionInformation()
/*      */   {
/*  815 */     IStatus status = this.databaseNameValidator.validate(this.databaseNameCombo.getText());
/*  816 */     if (!status.isOK()) {
/*  817 */       MessageDialog.openError(getSite().getShell(), "Invalid", status.getMessage());
/*  818 */       this.databaseNameCombo.setFocus();
/*  819 */       return false;
/*      */     }
/*      */ 
/*  822 */     boolean validDatabaseSchema = false;
/*  823 */     String databaseSchema = this.databaseSchemaText.getText();
/*      */ 
/*  825 */     ProfileConnector connector = new ProfileConnector(this.mappingData.getConnectionInformation());
/*  826 */     connector.connect();
/*  827 */     String[] schemas = connector.getSchemas();
/*      */ 
/*  829 */     String allowedSchemaText = "";
/*  830 */     if (schemas.length > 0) {
/*  831 */       for (String schema : schemas) {
/*  832 */         if (schema.equals(databaseSchema)) {
/*  833 */           validDatabaseSchema = true;
/*      */         }
/*  835 */         if (allowedSchemaText.length() > 0) {
/*  836 */           allowedSchemaText = allowedSchemaText + ", ";
/*      */         }
/*  838 */         allowedSchemaText = allowedSchemaText + schema;
/*      */       }
/*      */     }
/*  841 */     else if (databaseSchema.length() == 0) {
/*  842 */       validDatabaseSchema = true;
/*      */     }
/*      */ 
/*  846 */     if (!validDatabaseSchema) {
/*  847 */       MessageDialog.openError(getSite().getShell(), "Invalid", "Invalid schema name: " + databaseSchema + "\n" + "allowed schema names: \n" + allowedSchemaText);
/*  848 */       this.databaseSchemaText.setFocus();
/*      */     }
/*      */ 
/*  851 */     return validDatabaseSchema;
/*      */   }
/*      */ 
/*      */   private boolean validateGenerationInformation()
/*      */   {
/*  857 */     List<Entity> entityList = this.mappingData.getEntityList();
/*      */ 
/*  859 */     boolean generate = false;
/*  860 */     if (entityList != null) {
/*  861 */       for (Entity entity : entityList) {
/*  862 */         if (entity.isCreate()) {
/*  863 */           generate = true;
/*  864 */           break;
/*      */         }
/*      */       }
/*      */     }
/*      */ 
/*  869 */     if (!generate) {
/*  870 */       MessageDialog.openError(getSite().getShell(), "Invalid", "Select entities.");
/*  871 */       return false;
/*      */     }
/*      */ 
/*  874 */     for (Entity entity : entityList) {
/*  875 */       if (entity.isCreate()) {
/*  876 */         boolean validEntity = true;
/*      */ 
/*  878 */         if ((validEntity) && (!entity.isValidTableName())) {
/*  879 */           MessageDialog.openError(getSite().getShell(), "Invalid", "Table name '" + entity.getTableName() + "' is invalid.");
/*  880 */           validEntity = false;
/*      */         }
/*  882 */         if ((validEntity) && (!entity.isValidBaseName())) {
/*  883 */           MessageDialog.openError(getSite().getShell(), "Invalid", "Base name '" + entity.getBaseName() + "' is invalid.");
/*  884 */           validEntity = false;
/*      */         }
/*      */ 
/*  887 */         if (!validEntity) {
/*  888 */           Table entityTable = this.entityTableViewer.getTable();
/*      */ 
/*  890 */           TableItem[] tableItems = entityTable.getItems();
/*  891 */           for (int i = 0; i < tableItems.length; i++) {
/*  892 */             Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/*  894 */             if (entity == tableEntity) {
/*  895 */               entityTable.setSelection(i);
/*      */ 
/*  897 */               this.currentEntity = ((Entity)entityList.get(i));
/*  898 */               this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */             }
/*      */           }
/*      */ 
/*  902 */           return false;
/*      */         }
/*      */         TableItem[] tableItems;
/*  905 */         if (entity.getPrimaryKeyFieldList().size() == 0) {
/*  906 */           MessageDialog.openError(getSite().getShell(), "Invalid", "Table " + entity.getTableName() + "'s primary key required.");
/*      */ 
/*  908 */           Table entityTable = this.entityTableViewer.getTable();
/*      */ 
/*  910 */           tableItems = entityTable.getItems();
/*  911 */           for (int i = 0; i < tableItems.length; i++) {
/*  912 */             Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/*  914 */             if (entity == tableEntity) {
/*  915 */               entityTable.setSelection(i);
/*      */ 
/*  917 */               this.currentEntity = ((Entity)entityList.get(i));
/*  918 */               this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */             }
/*      */           }
/*      */ 
/*  922 */           return false;
/*      */         }
/*      */ 
/*  925 */         for (Entity e : entityList) {
/*  926 */           if ((entity != e) && (entity.isCreate()) && (e.isCreate()) && (entity.getBaseName().equals(e.getBaseName()))) {
/*  927 */             MessageDialog.openError(getSite().getShell(), "Invalid", "Duplicate base name.");
/*      */ 
/*  929 */             Table entityTable = this.entityTableViewer.getTable();
/*      */ 
/*  931 */              tableItems = entityTable.getItems();
/*  932 */             for (int i = 0; i < tableItems.length; i++) {
/*  933 */               Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/*  935 */               if (entity == tableEntity) {
/*  936 */                 entityTable.setSelection(i);
/*      */ 
/*  938 */                 this.currentEntity = ((Entity)entityList.get(i));
/*  939 */                 this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */               }
/*      */             }
/*      */ 
/*  943 */             return false;
/*      */           }
/*      */         }
/*      */ 
/*  947 */         for (Field field : entity.getFieldList()) {
/*  948 */           if (field.isCreate()) {
/*  949 */             boolean validField = true;
/*      */ 
/*  951 */             if ((validField) && (!field.isValidColumnName())) {
/*  952 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Column name '" + field.getColumnName() + "' is invalid.");
/*  953 */               validField = false;
/*      */             }
/*  955 */             if ((validField) && (!field.isValidColumnType())) {
/*  956 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Column type '" + field.getColumnType() + "' is invalid.");
/*  957 */               validField = false;
/*      */             }
/*  959 */             if ((validField) && (!field.isValidColumnLength())) {
/*  960 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Column size '" + field.getColumnSize() + "' is invalid.");
/*  961 */               validField = false;
/*      */             }
/*  963 */             if ((validField) && (!field.isValidNullable())) {
/*  964 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Nullable '" + field.isNullable() + "' is invalid.");
/*  965 */               validField = false;
/*      */             }
/*  967 */             if ((validField) && (!field.isValidFieldName())) {
/*  968 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Field name '" + field.getFieldName() + "' is invalid.");
/*  969 */               validField = false;
/*      */             }
/*  971 */             if ((validField) && (!field.isValidFieldType())) {
/*  972 */               MessageDialog.openError(getSite().getShell(), "Invalid", "Field type '" + field.getFieldType() + "' is invalid.");
/*  973 */               validField = false;
/*      */             }
/*      */ 
/*  976 */             if (!validField) {
/*  977 */               Table entityTable = this.entityTableViewer.getTable();
/*      */ 
/*  979 */                tableItems = entityTable.getItems();
/*  980 */               for (int i = 0; i < tableItems.length; i++) {
/*  981 */                 Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/*  983 */                 if (entity == tableEntity) {
/*  984 */                   entityTable.setSelection(i);
/*      */ 
/*  986 */                   this.currentEntity = ((Entity)entityList.get(i));
/*  987 */                   this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */ 
/*  989 */                   Table fieldTable = this.fieldTableViewer.getTable();
/*      */ 
/*  991 */                   TableItem[] fieldTableItems = fieldTable.getItems();
/*  992 */                   for (int j = 0; j < fieldTableItems.length; j++) {
/*  993 */                     Field tableField = (Field)fieldTableItems[j].getData();
/*      */ 
/*  995 */                     if (field == tableField) {
/*  996 */                       fieldTable.setSelection(j);
/*      */                     }
/*      */                   }
/*      */                 }
/*      */               }
/*      */ 
/* 1002 */               return false;
/*      */             }
/*      */           }
/*      */         }
/*      */ 
/* 1007 */         if (entity.hasDuplicateFieldName()) {
/* 1008 */           MessageDialog.openError(getSite().getShell(), "Invalid", "Duplicate field name.");
/*      */ 
/* 1010 */           Table entityTable = this.entityTableViewer.getTable();
/*      */ 
/* 1012 */           tableItems = entityTable.getItems();
/* 1013 */           for (int i = 0; i < tableItems.length; i++) {
/* 1014 */             Entity tableEntity = (Entity)tableItems[i].getData();
/*      */ 
/* 1016 */             if (entity == tableEntity) {
/* 1017 */               entityTable.setSelection(i);
/*      */ 
/* 1019 */               this.currentEntity = ((Entity)entityList.get(i));
/* 1020 */               this.fieldTableViewer.setInput(this.currentEntity.getFieldList());
/*      */             }
/*      */           }
/*      */ 
/* 1024 */           return false;
/*      */         }
/*      */       }
/*      */     }
/*      */ 
/* 1029 */     IStatus status = this.outputDirValidator.validate(this.outputDirText.getText());
/* 1030 */     if (!status.isOK()) {
/* 1031 */       MessageDialog.openError(getSite().getShell(), "Invalid", status.getMessage());
/* 1032 */       this.outputDirText.setFocus();
/* 1033 */       return false;
/*      */     }
/*      */ 
/* 1036 */     status = this.packageNameValidator.validate(this.packageNameText.getText());
/* 1037 */     if (!status.isOK()) {
/* 1038 */       MessageDialog.openError(getSite().getShell(), "Invalid", status.getMessage());
/* 1039 */       this.packageNameText.setFocus();
/* 1040 */       return false;
/*      */     }
/*      */ 
/* 1043 */     return true;
/*      */   }
/*      */ 
/*      */   private void showEntityList(List<Entity> entityList) {
/* 1047 */     if (entityList != null)
/* 1048 */       this.entityTableViewer.setInput(entityList.toArray());
/*      */     else {
/* 1050 */       this.entityTableViewer.setInput(null);
/*      */     }
/*      */ 
/* 1053 */     this.entityTableViewer.getTable().setSelection(-1);
/*      */ 
/* 1055 */     this.currentEntity = null;
/*      */ 
/* 1057 */     this.fieldTableViewer.setInput(null);
/* 1058 */     changeAllFieldSelection();
/*      */   }
/*      */ 
/*      */   protected void createPages()
/*      */   {
/* 1079 */     createMappingPage();
/* 1080 */     createSourcePage();
/*      */   }
/*      */ 
/*      */   public void createMappingPage() {
/* 1084 */     Composite parent = getContainer();
/*      */ 
/* 1086 */     ScrolledComposite scrolledComposite = new ScrolledComposite(parent, 768);
/* 1087 */     Composite contentComponent = new Composite(scrolledComposite, 0);
/* 1088 */     scrolledComposite.setContent(contentComponent);
/*      */ 
/* 1090 */     GridLayout layout = new GridLayout();
/* 1091 */     layout.numColumns = 3;
/* 1092 */     contentComponent.setLayout(layout);
/*      */ 
/* 1094 */     createConnectionInputPart(contentComponent);
/* 1095 */     createConnectionButtonPart(contentComponent);
/* 1096 */     createEntityTable(contentComponent);
/* 1097 */     createEntityButtonPart(contentComponent);
/* 1098 */     createFieldTable(contentComponent);
/* 1099 */     createFieldButtonPart(contentComponent);
/* 1100 */     createGenerationInputPart(contentComponent);
/* 1101 */     createGenerationButtonPart(contentComponent);
/*      */ 
/* 1103 */     contentComponent.pack();
/*      */ 
/* 1105 */     this.entityTableViewer.setInput(this.mappingData.getEntityList());
/*      */ 
/* 1107 */     bindValues();
/*      */ 
/* 1109 */     int index = addPage(scrolledComposite);
/* 1110 */     setPageText(index, "Mapping");
/*      */   }
/*      */ 
/*      */   public void createSourcePage() {
/*      */     try {
/* 1115 */       this.textEditor = new TextEditor();
/* 1116 */       int index = addPage(this.textEditor, getEditorInput());
/*      */ 
/* 1118 */       setPageText(index, "Source");
/*      */     }
/*      */     catch (PartInitException localPartInitException) {
/*      */     }
/*      */   }
/*      */ 
/*      */   public boolean isDirty() {
/* 1125 */     return (this.dirty) || (super.isDirty());
/*      */   }
/*      */ 
/*      */   public void doSave(IProgressMonitor monitor)
/*      */   {
/* 1130 */     if (getActivePage() == 0) {
/* 1131 */       updateSourceFromMapping();
/*      */     }
/* 1133 */     if (getActivePage() == 1) {
/* 1134 */       updateMappingFromSource();
/*      */     }
/*      */ 
/* 1137 */     this.textEditor.doSave(monitor);
/*      */ 
/* 1139 */     this.dirty = false;
/* 1140 */     firePropertyChange(257);
/*      */   }
/*      */ 
/*      */   public void doSaveAs()
/*      */   {
/* 1145 */     this.textEditor.doSaveAs();
/*      */ 
/* 1147 */     setInput(this.textEditor.getEditorInput());
/* 1148 */     setPartName(this.textEditor.getEditorInput().getName());
/*      */ 
/* 1150 */     this.dirty = false;
/* 1151 */     firePropertyChange(257);
/*      */   }
/*      */ 
/*      */   public void setFocus()
/*      */   {
/* 1156 */     if ((getActivePage() == 0) && (!isDirty()))
/* 1157 */       updateMappingFromSource();
/*      */   }
/*      */ 
/*      */   protected void pageChange(int newPageIndex)
/*      */   {
/* 1163 */     switch (newPageIndex) {
/*      */     case 0:
/* 1165 */       if (!isDirty()) break;
/* 1166 */       updateMappingFromSource();
/*      */ 
/* 1168 */       break;
/*      */     case 1:
/* 1170 */       if (!isDirty()) break;
/* 1171 */       updateSourceFromMapping();
/*      */     }
/*      */ 
/* 1176 */     super.pageChange(newPageIndex);
/*      */   }
/*      */ 
/*      */   private void updateMappingFromSource() {
/* 1180 */     String text = this.textEditor.getDocumentProvider().getDocument(this.textEditor.getEditorInput()).get();
/*      */ 
/* 1182 */     XmlData xmlData = new XmlData();
/*      */ 
/* 1184 */     this.mappingData = new MappingData();
/*      */     try
/*      */     {
/* 1187 */       xmlData.loadFromXml(text);
/*      */ 
/* 1189 */       this.mappingData = xmlData.getMappingData();
/*      */     }
/*      */     catch (Exception localException)
/*      */     {
/*      */     }
/* 1194 */     this.mappingData.addValueModifyListener(new DataModifyListener());
/*      */ 
/* 1196 */     bindValues();
/*      */ 
/* 1198 */     showEntityList(this.mappingData.getEntityList());
/*      */   }
/*      */ 
/*      */   private void updateSourceFromMapping() {
/* 1202 */     XmlData xmlData = new XmlData(this.mappingData);
/*      */ 
/* 1204 */     String text = "";
/*      */     try
/*      */     {
/* 1207 */       text = xmlData.getXmlText();
/*      */     }
/*      */     catch (XmlDataException localXmlDataException)
/*      */     {
/*      */     }
/* 1212 */     this.textEditor.getDocumentProvider().getDocument(this.textEditor.getEditorInput()).set(text);
/*      */   }
/*      */ 
/*      */   public class DataModifyListener
/*      */     implements ValueModifyListener
/*      */   {
/*      */     public DataModifyListener()
/*      */     {
/*      */     }
/*      */ 
/*      */     public void valueModified()
/*      */     {
/* 1063 */       MappingDataEditor.this.dirty = true;
/* 1064 */       MappingDataEditor.this.firePropertyChange(257);
/*      */     }
/*      */ 
/*      */     public boolean equals(Object obj)
/*      */     {
/* 1070 */       return (obj instanceof DataModifyListener);
/*      */     }
/*      */   }
/*      */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.editor.MappingDataEditor
 * JD-Core Version:    0.6.0
 */